/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Prestahop_retrievement;

import com.insa.a1.hibernate.ps.PsProduct;
import com.insa.a1.xmladapter.DateAdapter;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;

/**
 *
 * @author strokyl
 */
@Entity
public class Product implements Serializable {

	@Id
	private int idProduct;

	private String productName;
	private float price;

	@Temporal(TemporalType.TIMESTAMP)
	@XmlJavaTypeAdapter(DateAdapter.class)
	private Date dateUppAdd;

	@OneToMany(mappedBy = "cartProductPK.product")
	@XmlInverseReference(mappedBy = "cartProductPK.product")
	private Set<CartProduct> cartProducts;

	public Product(PsProduct psP) {
		this.idProduct = psP.getIdProduct();
		this.productName = psP.getDefaultName();
		this.price = psP.getPrice().floatValue();
		this.dateUppAdd = psP.getDateUpd();
		this.cartProducts = new HashSet<CartProduct>();
	}

	@Override
	public int hashCode() {
		int hash = 7;
		hash = 59 * hash + this.idProduct;
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Product other = (Product) obj;
		if (this.idProduct != other.idProduct) {
			return false;
		}
		return true;
	}

	public Product() {
	}

	public Date getDateUppAdd() {
		return dateUppAdd;
	}

	public void setDateUppAdd(Date dateUppAdd) {
		this.dateUppAdd = dateUppAdd;
	}

	public int getIdProduct() {
		return idProduct;
	}

	public void setIdProduct(int idProduct) {
		this.idProduct = idProduct;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	@Override
	public String toString() {
		return String.format("Product( %s, %s , %s )", idProduct, productName, price);
	}

	public Set<CartProduct> getCartProducts() {
		return cartProducts;
	}

	public void setCartProducts(Set<CartProduct> cartProducts) {
		this.cartProducts = cartProducts;
	}

}
